/*
 * BlurGlassDemo application
 *
 * Author: Cui.Yingyun
 *
 */

package com.laomou.password.ui;

import com.laomou.password.R;
import com.laomou.password.db.SQLiteHelper;


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class MainActivity extends Activity {
    private ListView mListView;
    private SQLiteHelper mLiteHelper;
    private ArrayAdapter mAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mListView = (ListView) findViewById(R.id.list);
        mLiteHelper = new SQLiteHelper(this, Password.class);
        mLiteHelper.delAll("account=?", new String[]{"Jhtf"});
        mAdapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, android.R.id.text1, mLiteHelper.findAll());
        mListView.setAdapter(mAdapter);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.main_menu, menu);
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onMenuItemSelected(int featureId, MenuItem item) {
        if (item.getItemId() == R.id.menu_newadd) {
            Intent intent = new Intent();
            intent.setClass(this, NewAddActivity.class);
            startActivityForResult(intent, 100);
        }
        return super.onMenuItemSelected(featureId, item);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == 100) {
            if (resultCode == 9) {
                mAdapter.notifyDataSetChanged();
            }
        }
        super.onActivityResult(requestCode, resultCode, data);
    }
}
